﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace SMS.Object
{
    public class MauXe
    {
        fLogin main;
        public MauXe(fLogin main1)
        {
            main = main1;
        }
        public string[] laytenmauxetonkho()
        {
            string[] result = null;
            string[] Temp = new string[10000];
            int i = 1;
            SqlConnection conn = new SqlConnection(main.ConnectDB);
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandText = "SELECT TENMAUXE FROM MAUXE ";

            //command.Parameters.Add(new SqlParameter("@LAN1", "Lần 1"));
            try
            {
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                Temp[0] = "Chọn tất cả";
                while (reader.Read())
                {
                   
                    Temp[i] = reader[0].ToString();
                    i++;
                }

                result = PerfectArray(Temp);


            }
            catch (SqlException ex)
            {
                string error = ex.Message;
            }
            finally
            {
                command.Dispose();
                conn.Close();
            }

            return result;
        }
        public DataTable laytenmauxe()
        {
            string sql = "SELECT TENMAUXE FROM MAUXE";
            return main.KetNoiDB.GetDataTable(sql);
        }
        public DataTable layMaMauXe()
        {
            string sql = "SELECT MAMAUXE FROM MAUXE";
            return main.KetNoiDB.GetDataTable(sql);
        }

        protected string[] PerfectArray(string[] array)
        {
            int count = 0;
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] != null)
                {
                    count++;
                }
            }
            string[] PerfectArray = new string[count];
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] != null)
                {
                    PerfectArray[i] = array[i];
                }
            }
            return PerfectArray;
        }

    }
}
